package com.woniuxy.qimengteacher.service.impl;

import com.woniuxy.qimengteacher.bean.SubjectBean;
import com.woniuxy.qimengteacher.mapper.SubjectMapper;
import com.woniuxy.qimengteacher.service.SubjectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表服务实现类
 *
 * @author makejava
 * @since 2020-08-25 19:43:21
 */
@Service("subjectService")
public class SubjectServiceImpl implements SubjectService {
    @Resource
    private SubjectMapper subjectMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectBean queryById(Integer id) {
        return this.subjectMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<SubjectBean> queryAllByLimit(int offset, int limit) {
        return this.subjectMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param subjectBean 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectBean insert(SubjectBean subject) {
        this.subjectMapper.insert(subject);
        return subject;
    }

    /**
     * 修改数据
     *
     * @param subjectBean 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectBean update(SubjectBean subject) {
        this.subjectMapper.update(subject);
        return this.queryById(subject.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.subjectMapper.deleteById(id) > 0;
    }
}